﻿namespace Nuclear.Models.DtoModels;

using static ErrorResponse;

public static class Errors
{
    public static ErrorDto InvalidSystemId(string systemId) =>
        new()
        {
            Code = ErrorCode.InvalidSystemId,
            Message = $"The system id {systemId} is invalid",
            UserMessage = $"系统ID {systemId}无效"
        };

    public static T InvalidSystemId<T>(string systemId) 
        where T : BaseResponseDto, new() =>
        Create<T>(InvalidSystemId(systemId));

    public static ErrorDto InvalidDateRange() =>
        new()
        {
            Code = ErrorCode.InvalidDateRange,
            Message = "The date range is invalid",
            UserMessage = "无效日期区间"
        };

    public static T InvalidDateRange<T>()
        where T : BaseResponseDto, new() =>
        Create<T>(InvalidDateRange());

    public static ErrorDto ConsumeCodeNotFound(string code) =>
        new()
        {
            Code = ErrorCode.ConsumeCodeNotFound,
            Message = $"The consume code {code} is not found",
            UserMessage = $"消费码{code}不存在"
        };

    public static T ConsumeCodeNotFound<T>(string code)
        where T : BaseResponseDto, new() =>
        Create<T>(ConsumeCodeNotFound(code));

    public static ErrorDto DuplicateConsumeCodeFound(string code) =>
        new()
        {
            Code = ErrorCode.DuplicateConsumeCodeFound,
            Message = $"Found multiple matches of the consume code {code}",
            UserMessage = $"消费码{code}出现多个匹配"
        };

    public static T DuplicateConsumeCodeFound<T>(string code)
        where T : BaseResponseDto, new() =>
        Create<T>(DuplicateConsumeCodeFound(code));

    public static ErrorDto ConsumeCodeAlreadyUsed(string code) =>
        new()
        {
            Code = ErrorCode.ConsumeCodeAlreadyUsed,
            Message = $"The consume code {code} is already used",
            UserMessage = $"消费码{code}已核销. 不可再次核销"
        };

    public static T ConsumeCodeAlreadyUsed<T>(string code)
        where T : BaseResponseDto, new() =>
        Create<T>(ConsumeCodeAlreadyUsed(code));

    public static ErrorDto ConsumeCodeExpired(string code) =>
        new()
        {
            Code = ErrorCode.ConsumeCodeExpired,
            Message = $"The consume code {code} has expired",
            UserMessage = $"消费码{code}已经过期"
        };

    public static T ConsumeCodeExpired<T>(string code)
        where T : BaseResponseDto, new() =>
        Create<T>(ConsumeCodeExpired(code));

    public static ErrorDto ConsumeCodeNotActiveYet(string code) =>
        new()
        {
            Code = ErrorCode.ConsumeCodeNotActiveYet,
            Message = $"The consume code {code} is not active yet",
            UserMessage = $"消费码{code}尚未到激活日期"
        };

    public static T ConsumeCodeNotActiveYet<T>(string code)
        where T : BaseResponseDto, new() =>
        Create<T>(ConsumeCodeNotActiveYet(code));

    public static ErrorDto InvalidRequest(string message, string userMessage) =>
        new()
        {
            Code = ErrorCode.InvalidRequest,
            Message = message,
            UserMessage = userMessage
        };

    public static T InvalidRequest<T>(string message, string userMessage)
        where T : BaseResponseDto, new() =>
        Create<T>(InvalidRequest(message, userMessage));

    public static ErrorDto Unauthorized() =>
        new()
        {
            Code = ErrorCode.Unauthorized,
            Message = "The access is unauthorized",
            UserMessage = "访问未授权"
        };

    public static T Unauthorized<T>()
        where T : BaseResponseDto, new() =>
        Create<T>(Unauthorized());

    public static ErrorDto InternalError() =>
        new()
        {
            Code = ErrorCode.InternalError,
            Message = "Internal server error",
            UserMessage = "服务器内部错误"
        };

    public static T InternalError<T>()
        where T : BaseResponseDto, new() =>
        Create<T>(InternalError());

    public static ErrorDto UserNameOrPasswordIncorrect() =>
        new()
        {
            Code = ErrorCode.UserNameOrPasswordIncorrect,
            Message = "The user name or the Password is incorrect",
            UserMessage = "用户名或者密码错误"
        };

    public static T UserNameOrPasswordIncorrect<T>()
        where T : BaseResponseDto, new() =>
        Create<T>(UserNameOrPasswordIncorrect());

    public static ErrorDto SystemLoginNotSupported(string systemId) =>
        new()
        {
            Code = ErrorCode.SystemLoginNotSupported,
            Message = $"The system with id {systemId} does not support login yet. Please contact the developer",
            UserMessage = $"{systemId}系统尚不支持登录, 请联系开发人员"
        };

    public static T SystemLoginNotSupported<T>(string systemId)
        where T : BaseResponseDto, new() =>
        Create<T>(SystemLoginNotSupported(systemId));
}